import React from 'react';
import { inject, observer } from "mobx-react";
import { Row } from 'antd'
import { WeaLocaleProvider } from 'ecCom'
import GoalLogs from '../../../public/loadlog/loadLogs';
import { toJS } from 'mobx';
import * as Util from "../../../util/Util";
const getLabel = WeaLocaleProvider.getLabel;
@inject("goalDetailStore")
@observer
export default class GoalOperateLog extends React.Component {

    constructor(props) {
        super(props);
    }

    
    componentWillMount() {//一些初始化请求
        const { goalDetailStore } = this.props;
        if(goalDetailStore.isFirstLog){
            goalDetailStore.getGoalLog({ goalId: goalDetailStore.detailKey, pagesize: '5', lastid: '' })
            goalDetailStore.isFirstLog = 0;
        }
    }

    componentWillReceiveProps(nextProps) {
    }
    
    componentDidMount(){
        const { goalDetailStore } = this.props;
        goalDetailStore.loading = false;
        // goalDetailStore.isFirstLog = 1;
    }

    //获取更多目标日志
    onMoreClick = (type, id, count) => {
        const { goalDetailStore:{detailKey} } = this.props;
        let params = {
            type: type,
            goalId: detailKey,
            pagesize: '5',
            lastid: id,
            lastcount: count
        }
        this.getGoalLog(params);
    }

    //获取目标的日志
    getGoalLog = (params) => {
        const { goalDetailStore } = this.props;
        goalDetailStore.getGoalLog(params);
    }

    //删除相关信息
    onLinkClick = (_id, _name, _type, _fileid, _filedname, _arrfiledname) => {
        const { goalDetailStore } = this.props;
        const { detailData,detailKey } = goalDetailStore;
        if (_type == 1) {
            if (_filedname == "goalids") {
                this.onNodeClick(_id);
            }
            if (_filedname == 'taskids') {
                window.open('/spa/workrelate/static/index.html?#/main/workrelate/task/taskDetail?id=' + _id);
            }
            if (_filedname == "fileids") {
                goalDetailStore.viewDocFiled({
                    id: _id, relateId: detailKey, type: 1, doback: function () {
                        Util.opendoc(_id);
                    }
                });
            }
        } else {  //下载
            goalDetailStore.viewDocFiled({
                id: _id, relateId: detailKey, type: 1, doback: function () {
                    Util.downloads(_fileid);
                }
            });
        }
    }

    onNodeClick = (key) => {
        if (key && key != '') {
            if(typeof this.props.renderDetail == "function"){
                this.props.renderDetail(key);
            }
        }
    }


    render() {
        const {goalDetailStore} = this.props;
        const {goalLog} = goalDetailStore;
        return (<div>
            <GoalLogs ecId={`${this && this.props && this.props.ecId || ''}_GoalLogs@vqe7b3`} logsData={goalLog.list} lastcount={goalLog.lastcount} onMoreClick={() => this.onMoreClick("more", goalLog.lastid, goalLog.lastcount)} onLinkClick={(id, name, type, columninfo) => this.onLinkClick(id, name, type, '', columninfo)} />
        </div>)
    }
}